/*
 * Copyright (c) 2021 Zsj. All rights reserved.
 */

package com.jzz.crawlerweb.handler.handler;

import com.jzz.crawlerweb.handler.data.CalculationCaptcha;
import com.jzz.crawlerweb.handler.data.Captcha;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class DataExport {
    private static final int count = 100;
    private static final String outDir = "";
    private static final String subDir = "calc/";

    public static void main(String[] args) throws IOException {
        File dir = new File(outDir + subDir);
        if (!dir.exists()) {
            dir.mkdirs();
        }

        CalculationCaptchaHandler handler = new CalculationCaptchaHandler();
        for (int i = 0; i < 100; i++) {
            Captcha captcha = handler.generate();
            if (captcha instanceof CalculationCaptcha) {
                File file = new File(dir, ((CalculationCaptcha) captcha).getHumanRaw() + ".jpg");
                if (!file.exists()) file.createNewFile();

                FileOutputStream fos = new FileOutputStream(file);
                fos.write(((CalculationCaptcha) captcha).getRendered());
                fos.flush();
                fos.close();
            }
        }
    }
}
